Skip to content

fix(admin): attach usage-tracking headers to Firestore requests - #308

Merged
demolaf merged 9 commits into
firestore/settings-headersfrom
firestore/admin-usage-headers
Jul 27, 2026
Merged

fix(admin): attach usage-tracking headers to Firestore requests#308
demolaf merged 9 commits into
firestore/settings-headersfrom
firestore/admin-usage-headers

Conversation

@demolaf

@demolaf demolaf commented Jul 23, 2026

Copy link
Copy Markdown
Member

Firestore requests never carried the SDK's usage-tracking headers (X-Firebase-Client, X-Goog-Api-Client) — FirestoreHttpClient builds its own HTTP client independently of FirebaseApp.client/FirebaseUserAgentClient, so it was never wrapped.

Uses the new Settings.headers from #307 to attach the same headers, and extracts a shared firebaseUserAgentHeaders helper so the values aren't duplicated between FirebaseUserAgentClient and Firestore. Depends on #307 merging first.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ensures that Firestore requests carry the SDK's usage-tracking headers (X-Firebase-Client and X-Goog-Api-Client) by extracting them into a shared utility and applying them to both FirebaseUserAgentClient and Firestore settings. The review feedback highlights two important improvements: first, instead of only applying tracking headers when no custom headers exist, they should be merged with any user-provided headers to prevent them from being completely omitted; second, the shared headers should be defined as a final variable rather than a getter to avoid redundant map allocations and regex evaluations on every HTTP request.

Comment thread packages/firebase_admin_sdk/lib/src/firestore/firestore.dart Outdated
Comment thread packages/firebase_admin_sdk/lib/src/utils/utils.dart Outdated
@github-actions

Copy link
Copy Markdown

Coverage Report

✅ Coverage 75.53% meets 40% threshold

Total Coverage: 75.53%
Lines Covered: 5228/6922

Package Breakdown

Package Coverage
firebase_admin_sdk 72.72%
google_cloud_firestore 78.69%

Minimum threshold: 40%

@demolaf
demolaf marked this pull request as ready for review July 24, 2026 12:04
@demolaf
demolaf requested a review from brianquinlan July 24, 2026 12:07
request.headers['X-Firebase-Client'] = 'fire-admin-dart/$packageVersion';
request.headers['X-Goog-Api-Client'] =
'gl-dart/$dartVersion fire-admin/$packageVersion';
request.headers.addAll(firebaseUserAgentHeaders);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this semantically different than what was there before?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, same values — just centralized into one shared constant instead of duplicated at each call site.

Comment thread packages/firebase_admin_sdk/CHANGELOG.md Outdated
@demolaf
demolaf merged commit e430080 into firestore/settings-headers Jul 27, 2026
15 checks passed
@demolaf
demolaf deleted the firestore/admin-usage-headers branch July 27, 2026 12:17
demolaf added a commit that referenced this pull request Jul 31, 2026
#307)

* fix(ci): use allow-listed codecov-action@v4 ref instead of a SHA pin

* test(ci): try pinning codecov-action to the actual v4 release SHA

* Revert "test(ci): try pinning codecov-action to the actual v4 release SHA"

This reverts commit 005b4a7.

* feat(firestore): add Settings.headers to attach custom request headers

* fix(firestore): append caller headers instead of overwriting existing X-Goog-Api-Client value

* test(firestore): add unit tests for FirestoreRequestClient header merging

* fix(firestore): address review feedback on Settings.headers

* fix(admin): attach usage-tracking headers to Firestore requests (#308)

* fix(admin): attach usage-tracking headers to Firestore requests

* refactor(admin): share usage-tracking header values between FirebaseUserAgentClient and Firestore

* fix(admin): avoid duplicate gl-dart tag when tagging Firestore requests

* fix(admin): address review feedback, merge rather than replace user headers

* docs(admin): wrap CHANGELOG entry to match surrounding style

* refactor(admin): extract shared identity strings to avoid duplicating them across the two header maps

* fix(ci): pin codecov-action to specific commit for stability

* Revert "fix(ci): pin codecov-action to specific commit for stability"

This reverts commit 9397148.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants